package com.vogue.supplymall.payment.dto;

import java.io.Serializable;

import com.vogue.supplymall.payment.tools.MD5Util;

/**
 * 回调接口输入参数对象<br>
 * 
 * @author 崔岳
 *
 */
public class CallbackInputParameter extends BaseDTO implements Serializable{

	/**
     * 
     */
    private static final long serialVersionUID = 8404376097349893787L;

    /** 门店ID */
	private String storeid;
	
	/** 第三方订单编号 */
	private String orderid;
	
	/** 订单来源，0线下，1线上 */
	private String ordfrom;
	
	/** 吾享订单号 */
	private String wxorderid;
	
	/** 微信/支付宝流水号 */
	private String payorderid;
	
	/** 支付类型，6微信，8支付宝 */
	private String paytypeid;
	
	/** 订单金额 */
	private String money;
	
	/** 订单状态，0-支付成功 */
	private String tradestate;
	
	/** 支付成功时间,yyyy-MM-dd HH:mm:ss */
	private String endtime;
	
	/** 以上字段的签名 <br>
	 * 
	 * sign计算方法。将待签名数据自然排列，并按照keyvalue的形式组合成待签名字符串，
	 * 结尾再加上密钥（如wuuxiang）。
	 * 结果如：orderidxxxordnoxxxpaydetailxxxxxpaymoney10.00paytypeid6storeidxxxtradeState0wuuxiang。
	 * 生成以base16编码的md5摘要字符串。回调失败会额外补发两次。*/
	private String sign;

	public String getStoreid() {
		return storeid;
	}

	public void setStoreid(String storeid) {
		this.storeid = storeid;
	}

	public String getOrderid() {
		return orderid;
	}

	public void setOrderid(String orderid) {
		this.orderid = orderid;
	}

	public String getOrdfrom() {
		return ordfrom;
	}

	public void setOrdfrom(String ordfrom) {
		this.ordfrom = ordfrom;
	}

	public String getWxorderid() {
		return wxorderid;
	}

	public void setWxorderid(String wxorderid) {
		this.wxorderid = wxorderid;
	}

	public String getPayorderid() {
		return payorderid;
	}

	public void setPayorderid(String payorderid) {
		this.payorderid = payorderid;
	}

	public String getPaytypeid() {
		return paytypeid;
	}

	public void setPaytypeid(String paytypeid) {
		this.paytypeid = paytypeid;
	}

	public String getMoney() {
		return money;
	}

	public void setMoney(String money) {
		this.money = money;
	}

	public String getTradestate() {
		return tradestate;
	}

	public void setTradestate(String tradestate) {
		this.tradestate = tradestate;
	}

	public String getEndtime() {
		return endtime;
	}

	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}
	
	public void validationProperty(String publickey64) throws Exception {
		StringBuffer buf = new StringBuffer();
		buf.append("endtime").append(getEndtime())
		.append("money").append(getMoney())
		.append("orderid").append(getOrderid())
		.append("ordfrom").append(getOrdfrom())
		.append("payorderid").append(getPayorderid())
		.append("paytypeid").append(getPaytypeid())
		.append("storeid").append(getStoreid())
		.append("tradestate").append(getTradestate())
		.append("wxorderid").append(getWxorderid())
		.append(publickey64);
		
		if(!(MD5Util.getMD5(buf.toString()).equals(getSign()))) {
			throw new Exception("数据不一致可能已被篡改");
		}

	}
	
	/**
	 * 获取数据一致性加工串
	 * @param publickey64 混淆加密串
	 * @return
	 * @throws Exception
	 */
	public String getValidationPropertyStr(String publickey64) throws Exception {
		StringBuffer buf = new StringBuffer();
		buf.append("endtime").append(getEndtime())
		.append("money").append(getMoney())
		.append("orderid").append(getOrderid())
		.append("ordfrom").append(getOrdfrom())
		.append("payorderid").append(getPayorderid())
		.append("paytypeid").append(getPaytypeid())
		.append("storeid").append(getStoreid())
		.append("tradestate").append(getTradestate())
		.append("wxorderid").append(getWxorderid())
		.append(publickey64);
		return MD5Util.getMD5(buf.toString());
	}
	
	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("[storeid:").append(getStoreid())
		.append(",orderid:").append(getOrderid())
		.append(",ordfrom:").append(getOrdfrom())
		.append(",wxorderid:").append(getWxorderid())
		.append(",payorderid:").append(getPayorderid())
		.append(",paytypeid:").append(getPaytypeid())
		.append(",money:").append(getMoney())
		.append(",tradestate:").append(getTradestate())
		.append(",endtime:").append(getEndtime())
		.append(",sign:").append(getSign()).append("]");
		return buf.toString();
	}
}
